from App import *
from TM1638 import *

class App1(App):
    def __init__(self):
        self.count = 0
        self.count1 = 0
        self.tm1638 = getTM1638()
    def foo(self):
        while True:
            self.count = self.count+1
            if(self.count > 0x0f):
                self.count = 0
            self.tm1638.write_NUM(0, self.count)
            
            yield SleepTask(1000)
    def foo2(self):
        while True:
            self.count1 = self.count1+1
            if(self.count1>7):
                self.count1 = 0
            self.tm1638.write_allLED(0x01<<self.count1)
            yield SleepTask(1000)
    
    def main(self):
        child = yield NewTask(self.foo())
        child1 = yield NewTask(self.foo2())
        print("sleep time", time.ticks_ms())
        yield SleepTask(10000)
        yield KillTask(child)
        yield KillTask(child1)
        print("exit count=", self.count, "time=", time.ticks_ms())
        
    
            
if __name__ == '__main__':
   
    app = App1()
    app.mainloop()
    